﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Demo0531
{
    //学生类
    //学生类：学号、姓名、年龄
    class Student:IComparable
    {
        public int StuNum { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public Student(int stuNum, string name, int age)
        {
            StuNum = stuNum;
            Name = name;
            Age = age;
        }
        public Student() { }
        public override string ToString()
        {
            return $"学号:{StuNum} 姓名:{Name} 年龄:{Age}";
        }
        public int CompareTo(object obj)
        {
            if (obj is Student)
            {
                return this.Age.CompareTo(((Student)obj).Age);
            }
            else
            {
                throw new Exception("搞错了，不是Student扔进来干嘛。");
            }
        }
    }
}
